#define _CRT_SECURE_NO_WARNINGS 1


class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n = nums.size();
        if (n == 1) return 1;
        int left = 0, ans = 0;
        for (int i = 0; i < n - 1; i++)
        {
            int right = nums[i + 1] - nums[i];
            if (right == 0) continue;
            if (left * right <= 0) ans++;
            left = right;
        }
        return ans + 1;
    }
};